<template>
  <el-descriptions
      class="margin-top"
      title="学生"
      border
  >
    <template #extra>
      <el-button @click="dialogFormVisible = true" type="primary" style="margin-right: 10px">新增</el-button>
      <el-dialog v-model="dialogFormVisible" title="新增">
        <el-form :model="form">
          <el-form-item label="学生账号" :label-width="formLabelWidth">
            <el-input v-model="form.account" autocomplete="off" type="textarea"/>
          </el-form-item>
          <el-form-item label="学生密码" :label-width="formLabelWidth">
            <el-input v-model="form.password" autocomplete="off" type="textarea"/>
          </el-form-item>
          <el-form-item label="学生姓名" :label-width="formLabelWidth">
            <el-input v-model="form.name" autocomplete="off" type="textarea"/>
          </el-form-item>
        </el-form>
        <template #footer>
      <span class="dialog-footer">
        <el-button @click="closeAdd">取消</el-button>
        <el-button type="primary" @click="save">
          新增
        </el-button>
      </span>
        </template>
      </el-dialog>
    </template>
  </el-descriptions>
</template>

<script setup>

import {reactive, ref} from 'vue'

import Student from "@/class/Student";
import axios from "axios";

const dialogFormVisible = ref(false)
const formLabelWidth = '140px'

const form = ref({
  id: '',
  account: '',
  password: '',
  name: ''
})

// const RuleFormRef = ref<FormInstance>({});

// const rules = reactive<FormRules>({
//   id: [{required: true, message: '请输入id', trigger: 'blur'}],
//   account: [{required: true, message: '请输入账号', trigger: 'blur'}],
//   password: [{required: true, message: '请输入密码', trigger: 'blur'}],
//   name: [{required: true, message: '请输入姓名', trigger: 'blur'}]
// })

const closeAdd = () => {
  dialogFormVisible.value = false;
}

const save = async () => {
  dialogFormVisible.value = false
  await
      axios.post('/student',form.value)
          .then(function (res){
            console.log(res.data)
          })
}
</script>

<style scoped>

.el-button--text {
  margin-right: 15px;
}

.el-select {
  width: 300px;
}

.el-input {
  width: 300px;
}

.dialog-footer button:first-child {
  margin-right: 10px;
}

.el-descriptions {
  margin-top: 20px;
}

.cell-item {
  display: flex;
  align-items: center;
}

.margin-top {
  margin-top: 20px;
}

.router-link-active {
  text-decoration: none;
  color: #00CC7E;
}
</style>